package com.lkl.test.demo.config;

import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetAddress;

@Configuration
@Slf4j
public class ElasticSearchConfig {

    @Bean
    /**
     * 获取es连接
     * @return
     * @throws Exception
     */
    public  TransportClient getClient() throws  Exception{
        Settings settings = Settings.builder()
                .put("cluster.name","docker-cluster")
                .put("client.transport.ping_timeout", "30s")
                .build();

        TransportClient client = new PreBuiltTransportClient(settings)
                .addTransportAddress(new TransportAddress(InetAddress.getByName("129.211.5.44"), 9300));
        return 		client ;
    }

}
